var names = [
	"info1","info2","info3","info4","info5","info6","info7"
];

var drawname;
var index = -1;
var time;
var flag = 1;

function btnOnclick() {
	if (flag % 2 == 1) {
		begin();
		document.getElementById("BTN").value = "按A暂停";
	}
	if (flag % 2 == 0) {
		end();
		document.getElementById("BTN").value = "按A开始";
	}
	flag++;
}

function begin() {
	document.getElementById("BTN").disabled = false;
	draw();
}

function draw() {
	if (names.length > 0) {
		index = Math.floor(Math.random() * 1000 % names.length);
		drawname = names[index];
		document.getElementById("result").innerHTML = drawname;

		time = window.setTimeout(draw, 2);
	} else {
		document.getElementById("result").innerHTML = "~请刷新网页~";
	}
}

function speech() {
	var url = "http://tts.youdao.com/fanyivoice?word=" + drawname + "&le=zh&keyfrom=speaker-target";
	new Audio(url).play();
}

function end() {
	speech();
	window.clearTimeout(time);
	document.getElementById("BTN").disabled = false;
	names.splice(index, 1);
}